package com.hubstc.book_borrow.controller;

import com.hubstc.book_borrow.pojo.Book;
import com.hubstc.book_borrow.pojo.PageBean;
import com.hubstc.book_borrow.pojo.Result;
import com.hubstc.book_borrow.service.BookService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController {

    @Resource
    private BookService bookService;

    @PostMapping("/add")
    public Result addBook(@RequestBody Book book){
        bookService.addBook(book);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<PageBean<Book>> list(
            Integer pageNum,
            Integer pageSize,
            @RequestParam(required = false) String bookCategory,
            @RequestParam(required = false) String bookName
    ){
        PageBean<Book> pageBean=bookService.list(pageNum,pageSize,bookCategory,bookName);
        return Result.success(pageBean);
    }

    @PutMapping("/update")
    public Result updateBook(@RequestBody Book book){
        bookService.updateBook(book);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result deleteBook(String bookId){
        bookService.deleteBook(bookId);
        return Result.success();
    }

}
